{% load i18n static fb_tags mezzanine_tags %}

{% if query.pop %}
<style>
h1 {margin:-30px 0 15px 0;}
</style>
{% endif %}

{% for file in page.object_list|dictsort:"filetype" %}
<tr class="{% cycle 'row1' 'row2' %}">

    <!-- FILESELECT FOR FILEBROWSEFIELD -->
    {% ifequal query.pop '1' %}
    {% if results_var.select_total %}
    <td class="fb_icon">
        {% selectable file.filetype query.type %}
        {% if selectable %}
        <a href="javascript://" onclick="FileSubmit('{{ file.path }}', '{{ file.url }}', '{{ settings_var.MEDIA_URL }}{% ifequal file.filetype 'Image' %}{% thumbnail file.path 60 60 %}{% else %}{{ file.path }}{% endifequal %}', '{{ file.filetype }}');" class="fb_selectlink" title="{% trans 'Select' %}"></a>
        {% else %}
        <img src="{{ settings_var.URL_FILEBROWSER_MEDIA }}img/filebrowser_icon_select_disabled.gif" width="23" height="17" />
        {% endif %}
    </td>
    {% endif %}
    {% endifequal %}

    <!-- FILESELECT FOR RTE/TINYMCE -->
    {% if query.pop == '2' or query.pop == '5' %}
    {% if results_var.select_total %}
    <td class="fb_icon">
        {% selectable file.filetype query.type %}
        {% if selectable %}
        <a href="javascript:FileBrowserDialogue.fileSubmit('{{ file.url|escapejs }}');" class="fb_selectlink" title="{% trans 'Select File' %}"></a>
        {% else %}
        <img src="{{ settings_var.URL_FILEBROWSER_MEDIA }}img/filebrowser_icon_select_disabled.gif" width="23" height="17" />
        {% endif %}
    </td>
    {% endif %}
    {% endif %}

    <!-- FILESELECT FOR CKEDITOR (FORMER "FCKEDITOR") -->
    {% ifequal query.pop '3' %}
    {% if results_var.select_total %}
    <td class="fb_icon">
        {% selectable file.filetype query.type %}
        {% if selectable %}
        <a href="#" onclick="OpenFile(ProtectPath('{{ file.url|escapejs }}'));return false;" class="fb_selectlink" title="{% trans 'Select File' %}"></a>
        {% else %}
        <img src="{{ settings_var.URL_FILEBROWSER_MEDIA }}img/filebrowser_icon_select_disabled.gif" width="23" height="17" />
        {% endif %}
    </td>
    {% endif %}
    {% endifequal %}

    <!-- GENERIC FILESELECT: opener grabs file url from rel attribute dynamically on click -->
    {% ifequal query.pop '4' %}
    {% if results_var.select_total %}
    <td class="fb_icon">
        {% selectable file.filetype query.type %}
        {% if selectable %}
        <a href="#" rel="{{ file.url|escape }}" class="fb_selectlink" title="{% trans 'Select File' %}"></a>
        {% else %}
        <img src="{{ settings_var.URL_FILEBROWSER_MEDIA }}img/filebrowser_icon_select_disabled.gif" width="23" height="17" />
        {% endif %}
    </td>
    {% endif %}
    {% endifequal %}

    <!-- FILEICON -->
    <td class="fb_icon"><img src="{{ settings_var.URL_FILEBROWSER_MEDIA }}img/filebrowser_type_{{ file.filetype|lower }}.gif" /></td>

    <!-- THUMBNAIL -->
    {% if results_var.images_total %}
    <td class="fb_icon">
        {% ifequal file.filetype 'Image' %}
        <a href="{{ file.url }}" target="_blank"><img src="{{ settings_var.MEDIA_URL }}{% thumbnail file.path 60 60 %}" title="{% trans 'View Image' %}" /></a>
        {% endifequal %}
    </td>
    {% endif %}

    <!-- FILENAME/DIMENSIONS -->
    {% ifequal file.filetype 'Folder' %}
    <td><b><a href="{% url "fb_browse" %}{% query_string "" "q,dir,p" %}&amp;dir={{ file.path_relative_directory|urlencode }}">{{ file.filename }}</a></b></td>
    {% else %}
    <td><b><a href="{{ file.url }}" target="_blank">{{ file.filename }}</a></b></td>
    {% endifequal %}

    <!-- RENAME -->
    {% if query.pop != '4' %}
    <td class="fb_icon"><a href="{% url "fb_rename" %}{% query_string %}&amp;filename={{ file.filename }}" class="fb_renamelink" title="{% trans 'Rename' %}"></a></td>
    {% endif %}

    <!-- SIZE -->
    <td>{{ file.filesize|filesizeformat }}</td>

    <!-- DATE -->
    <td>{{ file.datetime|date:"N j, Y" }}</td>

    <!-- DELETE -->
    <td class="fb_icon">
        {% ifnotequal file.filetype 'Folder' %}
        <form method="POST" action="{% url "fb_delete" %}{% query_string %}&amp;filename={{ file.filename }}&amp;filetype={{ file.filetype }}" id="delete-{{ forloop.counter0 }}">{% csrf_token %}</form>
        <a href="#" class="fb_deletelink" onclick="if (confirm('{% trans "Are you sure you want to delete this file?" %}')) {jQuery('#delete-{{ forloop.counter0 }}').submit();} return false;" title="{% trans 'Delete File' %}"></a>
        {% else %}
        <form method="POST" action="{% url "fb_delete" %}{% query_string %}&amp;filename={{ file.filename }}&amp;filetype={{ file.filetype }}" id="delete-{{ forloop.counter0 }}">{% csrf_token %}</form>
        <a href="#" class="fb_deletelink" onclick="if (confirm('{% trans "Are you sure you want to delete this Folder?" %}')) {jQuery('#delete-{{ forloop.counter0 }}').submit();} return false;" title="{% trans 'Delete Folder' %}"></a>
        {% endifnotequal %}
    </td>

    <!-- DEBUG -->
    {% if settings_var.DEBUG %}
    <td>
        <strong>Filename</strong> {{ file.filename }}<br />
        <strong>Filetype</strong> {{ file.filetype }}<br />
        <strong>Filesize</strong> {{ file.filesize }}<br />
        <strong>Extension</strong> {{ file.extension }}<br />
        <strong>Date</strong> {{ file.date }}<br />
        <strong>Datetime Object</strong> {{ file.datetime }}<br /><br />
        <strong>Relative Path</strong> {{ file.path_relative }}<br />
        <strong>Full Path</strong> {{ file.path_full }}<br />
        <strong>Relative URL</strong> {{ file.url_relative }}<br />
        <strong>Full URL</strong> {{ file.url }}<br /><br />
        <strong>URL for FileBrowseField</strong> {{ file.url }}<br />
        <strong>Thumbnail URL</strong> {{ file.url_thumbnail }}
        {% ifequal file.filetype 'Image' %}<br /><br />
        <strong>Dimensions</strong> {{ file.dimensions }}<br />
        <strong>Width</strong> {{ file.width }}<br />
        <strong>Height</strong> {{ file.height }}<br />
        <strong>Orientation</strong> {{ file.orientation }}
        {% endifequal %}
        {% ifequal file.filetype 'Folder' %}<br /><br />
        <strong>Is Empty</strong> {{ file.is_empty }}
        {% endifequal %}
    </td>
    {% endif %}

</tr>
{% endfor %}


